import os
import datetime
import logging

path = "E:\\study\\apitest\\wexcel"
dirname = os.path.dirname("E:\\study\\apitest\\wexcel")
print(dirname)
basename = os.path.basename("E:\\study\\apitest\\wexcel")
print("basename: {}".format(basename))
print(os.path.islink(path))
print(os.path.isabs(path))
print(os.path.split(path))

print("file abspath: {}".format(os.path.abspath(__file__)))

currentpath = os.path.dirname(os.path.abspath(__file__))
print(currentpath)
logpath = os.path.join(currentpath,'log')
print(logpath)
print(datetime.datetime.now())
print(datetime.datetime.today())
now = datetime.datetime.now()
print(now.month)
print(datetime.date.today())
newfilename = datetime.datetime.now().strftime("%Y%m%d_%H%M")
print(newfilename)
logfile = newfilename+".log"
print(logfile)

logname = logpath + "\\"+ logfile
print(logname)


logger = logging.getLogger()
logger.setLevel(logging.INFO)
file_hander = logging.FileHandler(logname)
formater = logging.Formatter("%(name)s---%(levelno)s--- %(levelname)s---%(pathname)s-- %(pathname)s --%(module)s---"
                             "%(message)s-- %(created)f-- %(asctime)s   ")
# file_hander.setLevel(logging.INFO)
file_hander.setFormatter(formater)
logger.addHandler(file_hander)
logger.info("it is message info")
file_hander.close()
logger.removeHandler(file_hander)


# file_handle = logging.FileHandler(log_name)
# formatter = logging.Formatter('%(asctime)s %(filename)s---> %(funcName)s %(levelno)s: %(levelname)s ----> %(message)s')
# file_handle.setFormatter(formatter)
# logger.addHandler(file_handle)
#
# logger.debug('test1233')
# file_handle.close()
# logger.removeHandler(file_handle)